
hirom
org $D4CA00


; Clear party member info
D4CA00:  STZ $75         ; Member A party info
         STZ $76         ; Member B party info
         STZ $77         ; Member C party info
         STZ $78         ; Member D party info
         LDY $00         ; SRAM block adr: $00
         STY $6D         ; Set for member A
         STY $6F         ; Set for member B
         STY $71         ; Set for member C
         STY $73         ; Set for member D
         LDA #$FF        ; Actor: None
         STA $69         ; Set as member A
         STA $6A         ; Set as member B
         STA $6B         ; Set as member C
         STA $6C         ; Set as member D
         RTL

warnpc $D4CA1D
org $D4CA1D

; Generate a gradient effect
D4CA1D:  XBA             ; Switch to B
         LDA $00         ; Clear it
         XBA             ; Gradient set
         ASL A           ; Double it
         TAX             ; Index it
         REP #$20        ; 16-bit A
         LDA $D4CA7C,X   ; Fixed color ptr
         STA $4332       ; Set CH3 src LBs
         LDA $D4CA71,X   ; Math desig. ptr
         STA $4342       ; Set CH4 src LBs
         SEP #$20        ; 8-bit A
         STZ $4330       ; CH3: 1Rx1B to PPU
         LDA #$32        ; CH3: $2132
         STA $4331       ; To fixed color
         LDA #$D4        ; Bank: D4
         STA $4334       ; Set CH3 src HB
         STA $4337       ; Set indir HB
         STA $4344       ; Set CH4 src HB
         STA $4347       ; Set indir HB
         STZ $4340       ; CH4: 1Rx1B to PPU
         LDA #$31        ; CH4: $2131
         STA $4341       ; To math desig.
         LDA #$18        ; Channels: 3+4
         TSB $43         ; Queue HDMA 3+4
         LDA #$80        ; Col math: Always
         STA $2130       ; Black clip: In
         LDA #$82        ; Col math: BG2
         STA $2131       ; Col math: Sub
         LDA #$17        ; BG1-BG3, OBJ
         STA $212C       ; Set main layers
         LDA #$17        ; ...
         STA $212D       ; Set sub layers
         LDA #$E0        ; RGB: 0
         STA $2132       ; Set fixed color
         RTL

; Pointers to color math designations
D4CA71:  dw D4CA77       ; Most menus
         dw D4CAB3       ; Save menus
         dw D4CAC4       ; Colosseum matchup

; Color math designation for most menus
D4CA77:  db $70,$02      ; BG2: Add mode
         db $70,$82      ; BG2: Sub mode
         db $00          ; End

; Pointers to gradient tables
D4CA7C:  dw D4CA82       ; Most menus
         dw D4CACD       ; Save menus
         dw D4CB42       ; Colosseum matchup

; Gradient table for most menus
D4CA82:  db $0A,$EB      ; RGB: 11
         db $0A,$EA      ; RGB: 10
         db $0A,$E9      ; RGB: 9
         db $0A,$E8      ; RGB: 8
         db $0A,$E7      ; RGB: 7
         db $0A,$E6      ; RGB: 6
         db $0A,$E5      ; RGB: 5
         db $0A,$E4      ; RGB: 4
         db $0A,$E3      ; RGB: 3
         db $0A,$E2      ; RGB: 2
         db $0A,$E1      ; RGB: 1
         db $0A,$E0      ; RGB: 0
         db $0A,$E1      ; RGB: 1
         db $0A,$E2      ; RGB: 2
         db $0A,$E3      ; RGB: 3
         db $0A,$E4      ; RGB: 4
         db $0A,$E5      ; RGB: 5
         db $0A,$E6      ; RGB: 6
         db $0A,$E7      ; RGB: 7
         db $0A,$E8      ; RGB: 8
         db $0A,$E9      ; RGB: 9
         db $0A,$EA      ; RGB: 10
         db $0A,$EB      ; RGB: 11
         db $0A,$EC      ; RGB: 12
         db $00          ; End

; Color math designation for save menus
D4CAB3:  db $1F,$02      ; BG2: Add mode
         db $10,$82      ; BG2: Sub mode
         db $1C,$02      ; BG2: Add mode
         db $1C,$82      ; BG2: Sub mode
         db $1C,$02      ; BG2: Add mode
         db $1C,$82      ; BG2: Sub mode
         db $1C,$02      ; BG2: Add mode
         db $1C,$82      ; BG2: Sub mode
         db $00          ; End

; Color math designation for Colosseum matchup menu
D4CAC4:  db $17,$02      ; BG2: Add mode
         db $78,$82      ; BG2: Sub mode
         db $24,$02      ; BG2: Add mode
         db $24,$82      ; BG2: Sub mode
         db $00          ; End

; Gradient table for save menus
D4CACD:  db $0F,$E0      ; RGB: 0
         db $02,$E7      ; RGB: 7
         db $02,$E6      ; RGB: 6
         db $02,$E5      ; RGB: 5
         db $02,$E4      ; RGB: 4
         db $02,$E3      ; RGB: 3
         db $02,$E2      ; RGB: 2
         db $02,$E1      ; RGB: 1
         db $02,$E0      ; RGB: 0
         db $02,$E1      ; RGB: 1
         db $02,$E2      ; RGB: 2
         db $02,$E3      ; RGB: 3
         db $02,$E4      ; RGB: 4
         db $02,$E5      ; RGB: 5
         db $02,$E6      ; RGB: 6
         db $02,$E7      ; RGB: 7
         db $04,$E7      ; RGB: 7
         db $04,$E6      ; RGB: 6
         db $04,$E5      ; RGB: 5
         db $04,$E4      ; RGB: 4
         db $04,$E3      ; RGB: 3
         db $04,$E2      ; RGB: 2
         db $04,$E1      ; RGB: 1
         db $04,$E0      ; RGB: 0
         db $04,$E1      ; RGB: 1
         db $04,$E2      ; RGB: 2
         db $04,$E3      ; RGB: 3
         db $04,$E4      ; RGB: 4
         db $04,$E5      ; RGB: 5
         db $04,$E6      ; RGB: 6
         db $04,$E7      ; RGB: 7
         db $04,$E6      ; RGB: 6
         db $04,$E5      ; RGB: 5
         db $04,$E4      ; RGB: 4
         db $04,$E3      ; RGB: 3
         db $04,$E2      ; RGB: 2
         db $04,$E1      ; RGB: 1
         db $04,$E0      ; RGB: 0
         db $04,$E1      ; RGB: 1
         db $04,$E2      ; RGB: 2
         db $04,$E3      ; RGB: 3
         db $04,$E4      ; RGB: 4
         db $04,$E5      ; RGB: 5
         db $04,$E6      ; RGB: 6
         db $04,$E7      ; RGB: 7
         db $04,$E6      ; RGB: 6
         db $04,$E5      ; RGB: 5
         db $04,$E4      ; RGB: 4
         db $04,$E3      ; RGB: 3
         db $04,$E2      ; RGB: 2
         db $04,$E1      ; RGB: 1
         db $04,$E0      ; RGB: 0
         db $04,$E1      ; RGB: 1
         db $04,$E2      ; RGB: 2
         db $04,$E3      ; RGB: 3
         db $04,$E4      ; RGB: 4
         db $04,$E5      ; RGB: 5
         db $04,$E6      ; RGB: 6
         db $00          ; End

; Gradient table for Colosseum matchup menu
D4CB42:  db $07,$E0      ; RGB: 0
         db $02,$E7      ; RGB: 7
         db $02,$E6      ; RGB: 6
         db $02,$E5      ; RGB: 5
         db $02,$E4      ; RGB: 4
         db $02,$E3      ; RGB: 3
         db $02,$E2      ; RGB: 2
         db $02,$E1      ; RGB: 1
         db $02,$E0      ; RGB: 0
         db $02,$E1      ; RGB: 1
         db $02,$E2      ; RGB: 2
         db $02,$E3      ; RGB: 3
         db $02,$E4      ; RGB: 4
         db $02,$E5      ; RGB: 5
         db $02,$E6      ; RGB: 6
         db $03,$E7      ; RGB: 7
         db $67,$E0      ; RGB: 0
         db $02,$EA      ; RGB: 10
         db $04,$E9      ; RGB: 9
         db $04,$E8      ; RGB: 8
         db $04,$E7      ; RGB: 7
         db $04,$E6      ; RGB: 6
         db $04,$E5      ; RGB: 5
         db $04,$E4      ; RGB: 4
         db $04,$E3      ; RGB: 3
         db $04,$E2      ; RGB: 2
         db $04,$E1      ; RGB: 1
         db $04,$E0      ; RGB: 0
         db $04,$E1      ; RGB: 1
         db $04,$E2      ; RGB: 2
         db $04,$E3      ; RGB: 3
         db $04,$E4      ; RGB: 4
         db $04,$E5      ; RGB: 5
         db $04,$E6      ; RGB: 6
         db $04,$E7      ; RGB: 7
         db $04,$E8      ; RGB: 8
         db $04,$E9      ; RGB: 9
         db $02,$EA      ; RGB: 10
         db $00          ; End

warnpc $D4CB8F
org $D4CB8F

; Queue general Mode 7 matrix HDMA
D4CB8F:  LDA #$42        ; 1Rx2B via ptrs
         STA $4340       ; Set for CH4
         STA $4350       ; Set for CH5
         STA $4360       ; Set for CH6
         STA $4370       ; Set for CH7
         LDA #$1B        ; CH4: $211B
         STA $4341       ; To matrix A
         INC A           ; CH5: $211C
         STA $4351       ; To matrix B
         INC A           ; CH6: $211D
         STA $4361       ; To matrix C
         INC A           ; CH7: $211E
         STA $4371       ; To matrix D
         LDY #D4CBE7     ; D4/CBE7
         STY $4342       ; Set CH4 src LBs
         LDY #D4CBEE     ; D4/CBEE
         STY $4352       ; Set CH5 src LBs
         LDY #D4CBF5     ; D4/CBF5
         STY $4362       ; Set CH6 src LBs
         LDY #D4CBE7     ; D4/CBE7
         STY $4372       ; Set CH7 src LBs
         LDA #$D4        ; Bank: D4
         STA $4344       ; Set CH4 src HB
         STA $4354       ; Set CH5 src HB
         STA $4364       ; Set CH6 src HB
         STA $4374       ; Set CH7 src HB
         LDA #$00        ; Indirect bank
         STA $4347       ; Set for CH4
         STA $4357       ; Set for CH5
         STA $4367       ; Set for CH6
         STA $4377       ; Set for CH7
         LDA #$F0        ; Channels: 4-7
         TSB $43         ; Queue HDMA 4-7
         RTL

; HDMA pointers for matrices A and D
D4CBE7:  db $FB,$04,$06  ; 123 lines, use $0604
         db $E5,$F8,$06  ; 101 lines, use $06F8
         db $00          ; End

; HDMA pointers for matrix B
D4CBEE:  db $FB,$C6,$07  ; 123 lines, use $07C6
         db $E5,$BA,$08  ; 101 lines, use $08BA
         db $00          ; End

; HDMA pointers for matrix C
D4CBF5:  db $FB,$88,$09  ; 123 lines, use $0988
         db $E5,$7C,$0A  ; 101 lines, use $0A7C
         db $00          ; End

warnpc $D4CBFC
org $D4CBFC

; Queue matrix, center X/Y, and BG1 position updating for sideview airship
D4CBFC:  LDA #$43        ; 2Rx2B via ptrs
         STA $4310       ; Set CH1 control
         STA $4320       ; Set CH2 control
         LDA #$42        ; 1Rx2B via ptrs
         STA $4340       ; Set CH4 control
         STA $4350       ; Set CH5 control
         STA $4360       ; Set CH6 control
         STA $4370       ; Set CH7 control
         LDA #$0D        ; CH1: $210D
         STA $4311       ; To BG1 Scroll
         LDA #$1F        ; CH2: $211F
         STA $4321       ; To center X+Y
         LDA #$1B        ; CH4: $211B
         STA $4341       ; To matrix A
         INC A           ; CH5: $211C
         STA $4351       ; To matrix B
         INC A           ; CH6: $211D
         STA $4361       ; To matrix C
         INC A           ; CH7: $211E
         STA $4371       ; To matrix D
         LDY #D4CD3A     ; D4/CD3A
         STY $4312       ; Set CH1 src LBs
         LDY #D4CD41     ; D4/CD41
         STY $4322       ; Set CH2 src LBs
         LDY #D4CD25     ; D4/CD25
         STY $4342       ; Set CH4 src LBs
         LDY #D4CD2C     ; D4/CD2C
         STY $4352       ; Set CH5 src LBs
         LDY #D4CD33     ; D4/CD33
         STY $4362       ; Set CH6 src LBs
         LDY #D4CD25     ; D4/CD25
         STY $4372       ; Set CH7 src LBs
         LDA #$D4        ; Bank: D4
         STA $4314       ; Set CH1 src HB
         STA $4324       ; Set CH2 src HB
         STA $4344       ; Set CH4 src HB
         STA $4354       ; Set CH5 src HB
         STA $4364       ; Set CH6 src HB
         STA $4374       ; Set CH7 src HB
         LDA #$00        ; Indirect bank
         STA $4347       ; Set for CH4
         STA $4357       ; Set for CH5
         STA $4367       ; Set for CH6
         STA $4377       ; Set for CH7
         LDA #$7E        ; Indirect bank
         STA $4317       ; Set for CH1
         STA $4327       ; Set for CH2
         LDA #$04        ; 4Rx1B to PPU
         STA $4330       ; Set CH3 control
         LDA #$30        ; CH3: $2130-3
         STA $4331       ; To color regs
         LDY #D4CC98     ; D4/CC98
         STY $4332       ; Set CH3 src LBs
         LDA #$D4        ; Bank: D4
         STA $4334       ; Set CH3 src HB
         STA $4337       ; Set indir bank
         LDA #$FE        ; Channels: 1-7
         TSB $43         ; Queue HDMA 1-7
         RTL

; HDMA table for the above ($2130-$2133)
D4CC98:  db $63          ; Lines: 99
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E0          ; Blank backdrop
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E1          ; Backdrop RGB: 1
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E2          ; Backdrop RGB: 2
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E3          ; Backdrop RGB: 3
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E4          ; Backdrop RGB: 4
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E5          ; Backdrop RGB: 5
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E6          ; Backdrop RGB: 6
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E7          ; Backdrop RGB: 7
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E8          ; Backdrop RGB: 8
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E9          ; Backdrop RGB: 9
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $EA          ; Backdrop RGB: 10
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $EB          ; Backdrop RGB: 11
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $EC          ; Backdrop RGB: 12
         db $00          ; Always 0...
         db $02          ; Lines: 2
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $EE          ; Backdrop RGB: 14
         db $00          ; Always 0...
         db $03          ; Lines: 3
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $F0          ; Backdrop RGB: 16
         db $00          ; Always 0...
         db $03          ; Lines: 3
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $F3          ; Backdrop RGB: 19
         db $00          ; Always 0...
         db $02          ; Lines: 2
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $F6          ; Backdrop RGB: 22
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $FA          ; Backdrop RGB: 26
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $FB          ; Backdrop RGB: 27
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $FC          ; Backdrop RGB: 28
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $EF          ; Backdrop RGB: 15
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $EC          ; Backdrop RGB: 12
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $EA          ; Backdrop RGB: 10
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E6          ; Backdrop RGB: 6
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E3          ; Backdrop RGB: 3
         db $00          ; Always 0...
         db $02          ; Lines: 2
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E2          ; Backdrop RGB: 2
         db $00          ; Always 0...
         db $03          ; Lines: 3
         db $80          ; Blacken sides
         db $01          ; BG1: Add colors
         db $E1          ; Backdrop RGB: 1
         db $00          ; Always 0...
         db $01          ; Lines: 1
         db $82          ; Blacken sides
                         ; Add credits to color math
         db $81          ; BG1: Subtract colors
         db $E0          ; Blank backdrop
         db $00          ; Always 0...
         db $00          ; End

; HDMA pointers for matrices A and D
D4CD25:  db $7C,$00,$06  ; 7E/0600; airship
         db $E4,$F8,$06  ; 7E/06F8; clouds
         db $00          ; End

; HDMA pointers for matrix B
D4CD2C:  db $7C,$C2,$07  ; 7E/07C2; airship
         db $E4,$BA,$08  ; 7E/08BA; clouds
         db $00          ; End

; HDMA pointers for matrix C
D4CD33:  db $7C,$84,$09  ; 7E/0984; airship
         db $E4,$7C,$0A  ; 7E/0A7C; clouds
         db $00          ; End

; HDMA pointers for BG1 scroll
D4CD3A:  db $7C,$8D,$B6  ; 7E/B68D; airship
         db $64,$91,$B6  ; 7E/B691; clouds
         db $00          ; End

; HDMA pointers for center X and Y
D4CD41:  db $7C,$95,$B6  ; 7E/B695; airship
         db $64,$99,$B6  ; 7E/B699; clouds
         db $00          ; End

warnpc $D4CD48
org $D4CD48

; Initialize registers for field menu
D4CD48:  LDA #$01        ; OBJ: 8x8, 16x16
         STA $2101       ; VRAM OBJ: $2000
         LDX $00         ; OBJ priority: Off
         STX $2102       ; OAM adr: $0000
         LDA #$09        ; BG tile: 8x8
         STA $2105       ; BG mode: 1+prio
         LDA #$00        ; Clear A
         STA $2106       ; Disable mosaic
         LDA #$03        ; 64x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$13        ; 64x64 at $1000
         STA $2108       ; Set BG2 map loc
         LDA #$43        ; 64x64 at $4000
         STA $2109       ; Set BG3 map loc
         LDA #$65        ; BG1 GFX: $5000
         STA $210B       ; BG2 GFX: $6000
         LDA #$66        ; BG3 GFX: $6000
         STA $210C       ; BG4 GFX: $6000
         TDC             ; Clear A
         STA $420C       ; Stop HDMA
         STA $420B       ; Stop DMA...
         STA $210D       ; BG1 H-Scroll LB
         STA $210D       ; BG1 H-Scroll HB
         STA $210E       ; BG1 V-Scroll LB
         STA $210E       ; BG1 V-Scroll HB
         STA $210F       ; BG2 H-Scroll LB
         STA $210F       ; BG2 H-Scroll HB
         STA $2110       ; BG2 V-Scroll LB
         STA $2110       ; BG2 V-Scroll HB
         STA $2111       ; BG3 H-Scroll LB
         STA $2111       ; BG3 H-Scroll HB
         STA $2112       ; BG3 V-Scroll LB
         STA $2112       ; BG3 V-Scroll HB
         STA $2113       ; BG4 H-Scroll LB
         STA $2113       ; BG4 H-Scroll HB
         STA $2114       ; BG4 V-Scroll LB
         STA $2114       ; BG4 V-Scroll HB
         LDA #$80        ; INC: 1 with HB
         STA $2115       ; Set video ctrl
         TDC             ; ...
         TAX             ; ...
         STX $2116       ; VRAM ptr: $0000
         STA $2121       ; CGRAM adr: $0000
         LDA #$3F        ; BG1 Win1/2: Out
         STA $2123       ; BG2 Win1: Out
                         ; BG2 Win2: Off
         LDA #$33        ; W1=Out, W2=Off
         STA $2124       ; Set for BG3, BG4
         STA $2125       ; Set for OBJ, Math
         LDA #$08        ; X: 8
         STA $2126       ; Set Win1-L
         STA $2128       ; Set Win2-L
         LDA #$F7        ; X: 247
         STA $2127       ; Set Win1-R
         STA $2129       ; Set Win2-R
         TDC             ; Clear A
         STA $212F       ; Sub: No masking
         STA $2133       ; Reset video flags
         STA $212A       ; BG logic: OR
         STA $212B       ; OBJ/Color: OR
         LDA #$1F        ; BG1-BG4, OBJ
         STA $212C       ; Set main layers
         LDA #$0F        ; BG1-BG3
         STA $212D       ; Set sub layers
         LDA #$0F        ; BG1-BG4 off in main..
         STA $212E       ; ..screen window area
         RTL

warnpc $D4CDF3
org $D4CDF3

; Reset menu or ending variables
D4CDF3:  TDC             ; Clear A
         TAY             ; Clear Y
         STY $BB         ; Matrix A
         STY $BD         ; Matrix B
         STY $BF         ; Matrix C
         STY $C1         ; Matrix D
         STY $B7         ; Center X
         STY $B9         ; Center Y
         STY $06         ; Pushed keys
         STY $08         ; No-autofire keys
         STY $0C         ; Former keys
         STY $0A         ; Semi-auto keys
         STY $97         ; Useless feature...
         STY $2B         ; Current anim fn
         STA $43         ; Active HDMA channels
         STA $26         ; Menu/scene mode
         STA $25         ; Main menu choice
         STA $B4         ; Event timer flag
         STA $B5         ; Mosaic settings
         STA $28         ; Former choice, etc.
         STA $29         ; Tile attributes
         STA $60         ; Face A queue index
         STA $61         ; Face B queue index
         STA $62         ; Face C queue index
         STA $63         ; Face D queue index
         STA $46         ; Sprite flags
         STA $66         ; Active save file
         STA $AE         ; Allow cursor SFX
         LDA #$FF        ; Cursor Y: 255
         STA $86         ; Set for face A
         STA $88         ; Set for face B
         STA $8A         ; Set for face C
         STA $8C         ; Set for face D
         LDA #$05        ; CGRAM: Refresh
         STA $45         ; Cursor: Show
         STY $1B         ; Null VRAM ptr2
         LDY #$4000      ; $4000
         STY $14         ; Set VRAM ptr1
         LDY #$7849      ; 7E/7849
         STY $16         ; Set src1 LBs
         LDA #$7E        ; Bank: 7E
         STA $18         ; Set src1 HB
         STA $1F         ; Set src2 HB
         LDY #$1000      ; Bytes: 4096
         STY $12         ; Set size 1
         STY $19         ; Set size 2
         LDA #$0C        ; VWF char width
         STA $B6         ; For SFC only...
         RTL

warnpc $D4CE55
org $D4CE55

; Set main screen designation per half-screen for final airship
D4CE55:  LDA #$70        ; Lines: 112
         STA $7E9D89     ; Set for HS1
         STA $7E9D8B     ; Set for HS2
         LDA #$11        ; On: BG1, OBJ
         STA $7E9D8A     ; Set for HS1
         STA $7E9D8C     ; Set for HS2
         STZ $4310       ; 1Rx1B to PPU
         LDA #$2C        ; $212C
         STA $4311       ; To MS desig.
         LDY #$9D89      ; 7E/9D89
         STY $4312       ; Set src LBs
         LDA #$7E        ; Bank: 7E
         STA $4314       ; Set src HB
         LDA #$7E        ; ...
         STA $4317       ; Set indir HB
         LDA #$02        ; Channel: 1
         TSB $43         ; Queue HDMA 1
         RTL

; Same parameter for entire screen, and there are no objects...


; Unused HDMA table (likely intended for the above)
D4CE86:  db $70,$89,$9D  ; 7E/9D89
         db $70,$89,$9D  ; 7E/9D89


warnpc $D4CE8C
org $D4CE8C

; Initialize registers for actor cinematic
D4CE8C:  LDA #$03        ; OBJ: 8x8, 16x16
         STA $2101       ; VRAM OBJ: $6000
         LDX $00         ; Clear X
         STX $2102       ; OAM adr: $0000
         LDA #$09        ; BG tile: 8x8
         STA $2105       ; BG mode: 1+prio
         LDA #$03        ; 64x64 at $0000
         STA $2107       ; Set BG1 map loc
         LDA #$11        ; 64x32 at $1000
         STA $2108       ; Set BG2 map loc
         LDA #$19        ; 64x32 at $1800
         STA $2109       ; Set BG3 map loc
         STA $210A       ; Set BG4 map loc
         LDA #$33        ; BG1 GFX: $3000
         STA $210B       ; BG2 GFX: $3000
         LDA #$22        ; BG3 GFX: $2000
         STA $210C       ; BG4 GFX: $2000
         JSR D4CF22      ; Set window info
         STZ $2130       ; Black clip: In
         LDA #$E0        ; RGB: 0
         STA $2132       ; Set fixed color
         LDA #$17        ; BG1-BG3, OBJ
         STA $212C       ; Set main layers
         LDA #$02        ; BG2
         STA $212D       ; Set sub layers
         LDA #$82        ; Col math: Add sub
         STA $2130       ; Black clip: In
         LDA #$D1        ; Col math: BG1+OBJ
         STA $2131       ; Col math: Hlf-Sub
         RTL

warnpc $D4CED7
org $D4CED7

; Initialize registers for ending credits
D4CED7:  LDA #$03        ; OBJ: 8x8, 16x16
         STA $2101       ; VRAM OBJ: $6000
         LDX $00         ; Clear X
         STX $2102       ; OAM adr: $0000
         LDA #$07        ; BG tile: 8x8
         STA $2105       ; BG mode: 7
         LDA #$58        ; 32x32 at $5800
         STA $2107       ; Set BG1 map loc
         LDA #$50        ; 32x32 at $5000
         STA $2108       ; Set BG2 map loc
         LDA #$7C        ; 32x32 at $7C00
         STA $2109       ; Set BG3 map loc
         STA $210A       ; Set BG4 map loc
         LDA #$44        ; BG1 GFX: $4000
         STA $210B       ; BG2 GFX: $4000
         LDA #$77        ; BG3 GFX: $7000
         STA $210C       ; BG4 GFX: $7000
         JSR D4CF22      ; Set window info
         STZ $211A       ; Mode 7: 128x128
         LDA #$13        ; BG1, BG2, OBJ
         STA $212C       ; Set main layers
         LDA #$10        ; OBJ
         STA $212D       ; Set sub layers
         LDA #$E0        ; RGB: 0
         STA $2132       ; Set fixed color
         LDA #$82        ; Col math: Add sub
         STA $2130       ; Black clip: In
         LDA #$81        ; Color math: BG1
         STA $2131       ; Color math: Sub
         RTL

; Set window boundaries and mask settings for ending scene
D4CF22:  LDA #$33        ; W1=Out, W2=Off
         STA $2123       ; Set for BG1, BG2
         STA $2124       ; Set for BG3, BG4
         LDA #$08        ; X: 8
         STA $2126       ; Set Win1-L
         STA $2128       ; Set Win2-L
         LDA #$F7        ; X: 247
         STA $2127       ; Set Win1-R
         STA $2129       ; Set Win2-R
         RTS

warnpc $D4CF3B
org $D4CF3B

; Back up field variables before ending scene
D4CF3B:  LDX $00         ; Index: 0
D4CF3D:  LDA $0600,X     ; Field data
         STA $7F4000,X   ; Make backup
         INX             ; Index +1
         CPX #$054C      ; At $0B4C?
         BNE D4CF3D      ; Loop if not
         RTL

warnpc $D4CF4B
org $D4CF4B

; Restore field variables after ending scene
D4CF4B:  LDX $00         ; Index: 0
D4CF4D:  LDA $7F4000,X   ; Data backup
         STA $0600,X     ; Restore it
         INX             ; Index +1
         CPX #$054C      ; At $0B4C?
         BNE D4CF4D      ; Loop if not
         RTL

warnpc $D4CF5B
